package com.example.mobile2032021606170hsy0522homework;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import org.jetbrains.annotations.NotNull;

import java.util.List;

public class NewsRVAdapter extends  RecyclerView.Adapter<NewsRVAdapter.ViewHolder>{
    private List<News>newsList;
    public  NewsRVAdapter(List<News> newsList){
        this.newsList =newsList;
    }
    @NonNull
    @NotNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_rv_main_news, parent,false);
        return  new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull @NotNull ViewHolder holder, int position) {
        News news=newsList.get(position);
        holder.tvItemID.setText(String.valueOf(news.getId()));
        holder.tvItemTitle.setText(news.getTitle());

    }

    @Override
    public int getItemCount() {
        return newsList.size();
    }

    static  class  ViewHolder extends RecyclerView.ViewHolder{
        TextView tvItemID,tvItemTitle;

        public ViewHolder(@NonNull @NotNull View itemView) {
            super(itemView);
            tvItemID = itemView.findViewById(R.id.tvItemID);
            tvItemTitle = itemView.findViewById(R.id.tvItemTitle);
        }
    }
}
